/**
 * 
 */
package de.oszimtcc.timetablehelper;

import java.io.IOException;
import java.io.StringReader;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import android.util.Log;
import de.oszimtcc.framework.Logger;
import de.oszimtcc.timetable.TimetableApplication;


/**
 * @author Kooki
 *
 */
public class Converter
{
	public static class DocumentConverter
	{
		public static Document DocFromString(String pToConvert)
		{
			Document doc = null;		
			DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
	        try 
	        {      	
				DocumentBuilder db = dbf.newDocumentBuilder();
				InputSource is = new InputSource();
		        is.setCharacterStream(new StringReader(pToConvert));
		        doc = db.parse(is); 	        
			} 
	        catch (ParserConfigurationException e) 
			{
	        	Logger.Error("XML parse error: " + e.getMessage());
				return null;
			} 
	        catch (SAXException e) 
			{
	        	Logger.Error("Wrong XML file structure: " + e.getMessage());
	            return null;
			} 
			catch (IOException e) 
			{
				Logger.Error("I/O exeption: " + e.getMessage());
				return null;
			}	
			
			return doc;
		}
	}
}
